package cn.weforward.task.impl;

import java.util.List;

import javax.annotation.Resource;

import cn.weforward.common.NameItem;
import cn.weforward.common.ResultPage;
import cn.weforward.common.util.StringUtil;
import cn.weforward.data.UniteId;
import cn.weforward.data.log.BusinessLog;
import cn.weforward.data.persister.support.AbstractPersistent;
import cn.weforward.task.Tag;
import cn.weforward.task.di.TaskDi;

public class SimpleTag extends AbstractPersistent<TaskDi> implements Tag{
	
	@Resource
	String m_Name;
	@Resource
	int m_State;

	
	protected SimpleTag(TaskDi di, String name, int state) {
		super(di);
		genPersistenceId();
		m_Name = name;
		m_State = state;
		markPersistenceUpdate();
	}
	protected SimpleTag(TaskDi di) {
		super(di);
	}

	@Override
	public UniteId getId() {
		return getPersistenceId();
	}

	@Override
	public String getName() {
		return m_Name;
	}

	@Override
	public void setName(String name) {
		//先判断设进来的name是否和该对象的name相等
		if (StringUtil.eq(name, m_Name)) {
			return;
		}
		//设置名字
		m_Name = name;
		markPersistenceUpdate();
		//日志
	}

	@Override
	public void show() {
		if(m_State == STATE_SHOW.id) {
			return;
		}
		
		//设置当前状态为显示中
		m_State = STATE_SHOW.id;
		markPersistenceUpdate();
	}

	@Override
	public void hide() {
		if(m_State == STATE_HIDE.id) {
			return;
		}
		//设置当前状态为隐藏
		m_State = STATE_HIDE.id;
		markPersistenceUpdate();
		
	}

	@Override
	public NameItem getState() {
		//根据当前id去查询状态
		return STATES.get(m_State);
	}
	
	@Override
	public ResultPage<BusinessLog> getLogs() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public ResultPage<SimpleTask> getTasks(String tagId) {
		// 查询该标签下的任务
		ResultPage<SimpleTask> rp = getBusinessDi().searchTasks(tagId);
		return rp;
	}



}
